import java.text.SimpleDateFormat
import play.api._
import models._
import play.api.db.slick._
import play.api.Play.current

object Global extends GlobalSettings {

  override def onStart(app: Application) {
    InitialData.insert()
  }

}

/**
 * Initial set of data to be imported 
 * in the sample application.
 */
object InitialData {

  val sdf = new SimpleDateFormat("yyyy-MM-dd")

  def insert(){
   DB.withSession{ implicit s:Session =>
    if (GroupDAO.count == 0) {
      Seq(
        Group(Option(1L), "JSF", Option("http://www.oracle.com/technetwork/java/javaee/javaserverfaces-139869.html")),
        Group(Option(2L), "RichFaces", Option("http://www.jboss.org/richfaces")),
        Group(Option(3L), "Commons Codec", Option("http://commons.apache.org/proper/commons-codec")),
        Group(Option(4L), "Commons IO", Option("http://commons.apache.org/proper/commons-io")),
        Group(Option(5L), "Hibernate Annotations", None),
        Group(Option(6L), "Hibernate Core", None),
        Group(Option(7L), "Facelets", Option("https://facelets.java.net")),
        Group(Option(8L), "Typesafe", Option("http://typesafe.com"))
      ).foreach(GroupDAO.insert)

      Seq(
        Resource(Option(1L), "Commons IO API", Option("2.2"), "http://commons.apache.org/proper/commons-io/javadocs/api-2.2/index.html", 4L),
        Resource(Option(2L), "Commons IO API", Option("2.4"), "http://commons.apache.org/proper/commons-io/javadocs/api-release/index.html", 4L),
        Resource(Option(3L), "JSF", Option("1.1.01"), "file:///path/to/resource.ext", 1L),
        Resource(Option(4L), "RichFaces Components API", Option("4.0.0"), "file:///path/to/resource.ext", 2L),
        Resource(Option(5L), "RichFaces API", Option("3.3.0.GA"), "file:///path/to/resource.ext", 2L),
        Resource(Option(6L), "RichFaces Developers Guide", Option("3.3.0.GA"), "file:///c:/path/to/resource.ext", 2L),
        Resource(Option(7L), "Scala API", Option("2.9.1.final"), "file:///c:/path/to/resource.ext", 8L),
        Resource(Option(8L), "Scala API", Option("2.10.3"), "file:///c:/path/to/resource.ext", 8L),
        Resource(Option(9L), "Play", Option("2.1.0"), "file:///c:/path/to/resource.ext", 8L),
        Resource(Option(10L), "Play", Option("2.2.0"), "file:///c:/path/to/resource.ext", 8L),
        Resource(Option(11L), "Slick", Option("1.0.1"), "file:///c:/path/to/resource.ext", 8L)
      ).foreach(ResourceDAO.insert)
    }
   }
  }
}
